package com.lry.basic.redis.readWriteLock;

import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        final int[] num = {0};
        for (int i = 0; i < 10 ; i++) {
            Thread thread = new Thread(() -> {
                RedisReadWriteLock.writeLock().tryLock("ccc", 3,10, TimeUnit.SECONDS);
                num[0]++;
                System.out.println("【写】：" + num[0]);
                RedisReadWriteLock.writeLock().unlock("ccc");
            });
            thread.start();
        }
        for (int i = 0; i < 100 ; i++) {
            Thread thread = new Thread(() -> {
                RedisReadWriteLock.readLock().tryLock("ccc", 3,10, TimeUnit.SECONDS);

                System.out.println("读：" + num[0]);

                RedisReadWriteLock.readLock().unlock("ccc");
            });
            thread.start();
            if(i % 3 == 0){
                try {
                    TimeUnit.MILLISECONDS.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
